package com.bite.book.config;

import com.bite.book.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody
@ControllerAdvice
@Slf4j
public class ExceptionAdvice {
    @ExceptionHandler
    private Result handler(Exception e){
        log.error("发生异常，e1: ",e.getMessage());
        return Result.FAIL("内部错误,请联系管理员!");
    }

    @ExceptionHandler
    private Result handler(NullPointerException e){
        log.error("发生异常，e2: ",e.getMessage());
        return Result.FAIL("空指针异常,请联系管理员!");
    }

    @ExceptionHandler
    private Result handler(IndexOutOfBoundsException e){
        log.error("发生异常，e3: ",e.getMessage());
        return Result.FAIL("内存益处异常,请联系管理员!");
    }
}
